package zengjin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.PageResponse;
import zengjin.common.R;
import zengjin.model.dto.send.AddSendRequest;
import zengjin.model.dto.send.PageSendRequest;
import zengjin.model.vo.send.JobAndResumeVO;
import zengjin.model.vo.send.PageJobAndResumeVO;
import zengjin.service.SendService;

/**
 * @author 19324
 */
@Tag(name = "投递相关接口")
@RestController
@RequestMapping("/send")
@Slf4j
public class SendController {

    @Resource
    private SendService sendService;

    //1. 添加投递
    @Operation(summary = "添加投递")
    @PostMapping("/addSend")
    public R<Boolean>  addSend(@RequestBody AddSendRequest addSendRequest) {
        //1.参数校验
        if (addSendRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        boolean result = sendService.addSend(addSendRequest);
        if(!result){
            return R.error(false, "添加投递失败");
        }
        return R.success(true, "添加投递成功");

    }

    //2.查询是否投递
    @Operation(summary = "查询是否投递根据Id")
    @PostMapping("/isSend")
    public R<Long>  isSend(Long sendJobseekerId,Long sendEmployerId, Long sendJobId) {
        //1.参数校验
        if (sendJobseekerId == null || sendEmployerId == null || sendJobId == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        long result = sendService.isSend(sendJobseekerId,sendEmployerId,sendJobId);
        return R.success(result, "查询是否投递成功");
    }

    //3.更新投递状态
    @Operation(summary = "更新投递状态")
    @PostMapping("/updateSendStatus")
    public R<Boolean>  updateSendStatus(Long sendId,String sendStatus) {
        //1.参数校验
        if (sendId == null || sendStatus == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        boolean result = sendService.updateSendStatus(sendId,sendStatus);
        if(!result){
            return R.error(false, "更新投递状态失败");
        }
        return R.success(true, "更新投递状态成功");
    }

    //4.删除投递
    @Operation(summary = "删除投递")
    @PostMapping("/deleteSend")
    public R<Boolean>  deleteSend(Long sendId) {
        //1.参数校验
        if (sendId == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        boolean result = sendService.removeById(sendId);
        if(!result){
            return R.error(false, "删除投递失败");
        }
        return R.success(true, "删除投递成功");
    }

    //5.分页查询投递
    @Operation(summary = "分页查询投递")
    @PostMapping("/pageSend")
    public R<PageResponse<PageJobAndResumeVO>>  pageSend(@RequestBody PageSendRequest pageSendRequest) {
        //1.参数校验
        if (pageSendRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        PageResponse<PageJobAndResumeVO> result = sendService.pageSend(pageSendRequest);
        if(result == null){
            return R.error(null, "分页查询投递失败");
        }
        return R.success(result, "分页查询投递成功");
    }

    //6.根据投递Id查询投递详情
    @Operation(summary = "根据投递Id查询投递详情")
    @PostMapping("/getSendById")
    public R<JobAndResumeVO>  getSendById(Long sendId) {
        //1.参数校验
        if (sendId == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        JobAndResumeVO result = sendService.getSendById(sendId);
        if(result == null){
            return R.error(null, "根据投递Id查询投递详情失败");
        }
        return R.success(result, "根据投递Id查询投递详情成功");
    }
}
